from typing import List


class Solution:
    def wordBreak(self, s: str, wordDict: List[str]) -> bool:
        len_word_list  = []
        for i in wordDict:
            len_word_list.append(len(i))
        print(len_word_list)
        start = 0
        end = 0
        self.flag = 0
        self.false_flag = 0
        def dfs(start,end) ->bool:
            if self.flag ==1:
                return True
            if self.false_flag == 1:
                return False
            for j,i  in enumerate( len_word_list):
                if self.false_flag == 1:
                    return False
                if self.flag == 1:
                    return True
                if end + i >len(s):
                    if j == len(len_word_list) - 1:
                        print("我已经返回了错误了")
                        self.false_flag = 1
                        return False
                    else:
                        continue
                if s[start:end+i] in wordDict:
                    print(s[start:end+i])
                    if end+i == len(s):
                        print("return l true")
                        self.flag = 1
                        return True
                    print('start' ,end)
                    print('end',end+i)
                    dfs(start+i,end+i)
                if j== len(len_word_list)-1:
                    if self.flag == 1:
                        return True
                    print("我已经返回了错误了")
                    self.false_flag = 1
                    return False






        print(dfs(start,end) ,"结果是？")
        if self.flag == 1:
            print("pril")
            return True
        else:
            return False









if __name__ == '__main__':
    s ="cars"
    print(len(s))
    wordDict =["car","ca","rs"]
    solution = Solution()
    val = solution.wordBreak(s,wordDict)
    print(val)